<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
    <link rel="stylesheet" href="<s:url value="/assets/css/main.css"></s:url>"/>
</head>
<style>
    #laydate_today {
        display: none !important;
    }
</style>
<body class="no-skin">
<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>
<!-- /section:basics/navbar.layout -->

<%--修改模态框--%>
<div class="modal fade" id="modify" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
     data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改</h4></div>
            <div class="modal-body ">
                <div class="form-group clearfix">
                    <label class="control-label col-sm-2 text-right">任务名称</label>
                    <div class="col-sm-9">
                        <input type="text" class="Modelname form-control" name="mainName">
                    </div>
                </div>
                <%--时限 类型--%>
                <div class="form-group clearfix">
                    <label class="control-label col-sm-2 text-right">任务内容</label>
                    <div class="col-sm-9">
                        <textarea type="text" class="form-control" name="content"></textarea>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="control-label col-sm-2 text-right">任务时限</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control date_picker transform" name="timeLimit" readonly>
                    </div>
                </div>
                <%--附件--%>
                <%--<div class="form-group clearfix downloadFile">--%>
                <%--<label class="control-label col-sm-2 text-right">附件下载</label>--%>
                <%--<div class="col-sm-9">--%>
                <%--<input type="text" readonly>--%>
                <%--<button class="btn btn-primary" FileSysId="" onclick="download(this)"><span class="glyphicon glyphicon-save"></span>下载附件</button>--%>
                <%--</div>--%>
                <%--</div>--%>
                <div class="form-group clearfix">
                    <label class="control-label col-sm-2 text-right">任务附件</label>
                    <div class="col-sm-9 pos-rel">
                        <%--附件回显容器--%>
                        <div class="downloadContainer"></div>
                        <div id="uploader"></div>
                        <%-- <div>
                             <div style="display: inline-block">
                                 <input type="file" class="fileBorder" id="fileupload">
                             </div>
                             <div style="display: inline-block">
                                 <button class="btn btn-info" onclick="uploadFile(this,'file','fileName')">
                                     <span class="glyphicon glyphicon-open"></span>上传附件
                                 </button>
                             </div>
                         </div>--%>
                    </div>
                    <input hidden id="temporaryFile" name="file">
                    <input hidden id="temporaryFileName" name="fileName">
                </div>
                <input type="hidden" name="sysId">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success confirmModify" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>


<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <!-- /section:settings.box -->
                <h3 class="text-center">我派发的任务</h3>
                <%--搜索栏--%>
                <div>
                    <select class="searchType" style="width: 210px;" onchange="searchTable('/taskMain/allMain/')">
                        <option value="">请点击选择搜索事项类型</option>
                    </select>
                    <%--承办单位--%>
                    <select multiple="true" onchange="searchTable('/taskMain/allMain/')" class="deptIds" id="deptIds1"
                            placeholder="请输入或点击选择承办单位"
                            style="width: 210px;height: 33px;"></select>
                    <%-- 储存部门id--%>
                    <input type="text" value="" name="" class="deptrespts" hidden>
                    <input type="text" class="beginTimes form-control date-picker" placeholder="请选择开始时间"
                           title="请选择开始时间"
                           style="width: 210px;display: inline-block;" onchange="searchTable('/taskMain/allMain/')">

                    <input type="text" class="endTimes form-control date-picker" placeholder="请选择结束时间"
                           title="请选择结束时间"
                           style="width: 210px;display: inline-block;" onchange="searchTable('/taskMain/allMain/')">
                </div>
                <div style="margin-top:10px;">
                    <input type="text" style="width: 280px;" class="searchs" placeholder="请输入搜索内容"
                           onchange="searchTable('/taskMain/allMain/')">
                    <button class="btn btn-primary search-btns" onclick="searchTable('/taskMain/allMain/')">搜索</button>
                    <button class="btn btn-primary resets">重置</button>
                    <button class="btn btn-primary" id="noFinish">未完成</button>
                    <button class="btn btn-primary" id="finished">已完成</button>
                    <button class="btn btn-primary" id="allMain">全部任务</button>
                </div>
                <%--以上为搜索--%>
                <div class="col-xs-6">
                    <%--<div class="pull-right">--%>
                    <%--搜索:<input type="text" name="category">--%>
                    <%--<button class="btn btn-success categoryConfirm"--%>
                    <%--onclick="confirmBtn(this,'category','/common/releaseBriefing/briefCategory/')">确定</button>--%>
                    <%--</div>--%>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <table id="gridTable"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager"></div>
                        <!-- 查询对话框 -->
                        <div style="display: none;">
                            <div class="row" id="queryDialog"></div>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
                <c:if test="${roleId == '01'}">
                    <h3 class="text-center">抄送我的</h3>
                    <div class="row">
                        <div class="col-xs-12">
                            <!-- PAGE CONTENT BEGINS -->
                            <!-- jqGrid表格 -->
                            <table id="gridTable1"></table>
                            <!-- jqGrid工具类 -->
                            <div id="gridPager1"></div>
                        </div><!-- /.col -->
                    </div>
                    <!-- /.page-content -->
                </c:if>
                <c:if test="${dept.sysId == '20190722100000000194'}">
                    <h3 class="text-center">攻坚办的攻坚任务</h3>
                    <div class="row">
                        <div class="col-xs-12">
                            <!-- PAGE CONTENT BEGINS -->
                            <!-- jqGrid表格 -->
                            <table id="gridTable2"></table>
                            <!-- jqGrid工具类 -->
                            <div id="gridPager2"></div>
                            <!-- 查询对话框 -->
                            <div style="display: none;">
                                    <%--<div class="row" id="queryDialog"></div>--%>
                            </div>
                            <!-- PAGE CONTENT ENDS -->
                        </div><!-- /.col -->
                    </div>
                    <!-- /.row -->
                </c:if>
                <h4 class="redTips">温馨提示：双击表格行或者点击"查看" 查看任务列表</h4>
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>

    <%@ include file="/WEB-INF/views/include/dialog.jsp" %>
</div><!-- /.main-container -->
</div>

<!-- footer -->
<%--多选上传--%>
<script src="<s:url value="/assets/js/dist/easyUploader.jq.js"></s:url>"></script>
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<script src="<s:url value="/assets/js/own.js"></s:url>"></script>

<script type="text/javascript">
    // 基本路径
    var baseUrl = "<s:url value="/taskMain/allMain/"></s:url>"

    // jqgrid的表格高度
    var height = 320;
    // jqgrid表格行头的中文
    var colNames = ['', '任务名称', "事项类型", "状态", "办理时限", "逾期说明", "状态说明", "任务派发", "操作"];
    var colNames2 = ['', '任务名称', "任务内容", "督查组单位", "附件名字", "状态", "操作"];//攻坚

    var colModel = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'mainName', index: 'mainName', width: 250, editable: true},
        {name: 'categoryId', index: 'categoryId', width: 250, editable: true, formatter: categoryIdFormatter},
        {name: 'status', index: 'status', width: 150, editable: true, formatter: typeFormatter},
        {name: 'timeLimit', index: 'timeLimit', width: 150, editable: true},
        {name: 'typeExplain', index: 'typeExplain', width: 350, editable: true},
        {name: 'overdueExplain', index: 'overdueExplain', width: 250, editable: true},
        {name: 'crucialUser', index: 'crucialUser', width: 150, editable: true, formatter: crucialUserFormatter},
        {name: 'sy', width: 250, align: "center", formatter: feedbackBtnFormatter}
    ];

    //攻坚
    var colModel2 = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'mainName', index: 'mainName', width: 250, editable: true},
        {name: 'content', index: 'content', width: 250, editable: true},
        {name: 'inspectionId', index: 'inspectionId', width: 250, editable: true, formatter: inspectionIdFormatter},
        // {name: 'gJFile', index: 'gJFile', width: 100,align : "center", editable: true,formatter:fileFormatter},
        {name: 'gJFileName', index: 'gJFileName', width: 250, editable: true},
        {name: 'status', index: 'status', width: 150, editable: true, formatter: typeFormatter},
        {name: 'sy', index: 'sy', width: 150, align: "center", formatter: urgentFormatter}
    ];


    function feedbackBtnFormatter(value, grid, rows, state) {
        grid.colModel.title = false
        return "<div style='color: #049CE6;display: flex;justify-content: center'>" +
            "<div style='width: 40px;cursor: pointer' title='查看'id='feedbackBtn'>查看</div>" +
            "<div class='establish' style='width: 40px;border-left:1px solid #049CE6;cursor: pointer; display: " + (rows.status == 9 ? "block" : "none") + "' title='立项'>立项</div>" +
            "<div class='handle' style='width: 100px;border-left:1px solid #049CE6;cursor: pointer;' title='办理情况导出'>办理情况导出 </div>" +
            "<div style='border-left:1px solid #049CE6;width: 40px;cursor: pointer'title='修改' class='modify' >修改</div>" +
            "<div class='deteleTask' style='width: 40px;border-left:1px solid #049CE6;cursor: pointer;display:" + (!rows.crucialUser ? "block" : "none") + "' title='删除'>删除</div>" +
            "</div>";
    }

    /*是否攻坚*/
    function crucialUserFormatter(data) {
        if (data) {
            return "攻坚作战室"
        } else {
            return "督查组"
        }
    }

    /**
     * 督查组单位id转换
     */
    function inspectionIdFormatter(data) {
        $.ajax({
            url: "/taskCrucial/getInspectionId/",
            type: "get",
            async: false,
            success: function (datas) {
                for (key in datas.data) {
                    if (datas.data[key].sysId == data) {
                        data = datas.data[key].deptName;
                    }
                }
            }
        });
        return data
    }

    /**
     * 逾期类型格式化
     */
    function statusFormatter(data) {
        return data == 9 ? '待立项 ' : '已立项'
    }

    /**
     *攻坚按钮
     */
    function urgentFormatter(value, grid, rows, state) {
        grid.colModel.title = false
        var html = "<div style='color: #049CE6;display: flex;justify-content: center'>"
        html += "<div style='width: 40px;cursor: pointer' id='urgentSee' title='查看'>查看</div>" + "<div class='deteleTask' style='width: 40px;border-left:1px solid #049CE6;cursor: pointer;' title='删除'>删除</div>"
        html += "</div>"
        return html;
    }

    /**
     * 任务类型格式化
     */
    function categoryIdFormatter(data) {
        let mz = '';
        $.ajax({
            url: "/taskMain/categoryName/" + data,
            type: "get",
            dataType: 'json',
            async: false,
            success: function (data) {
                mz = data.category;
            }
        })
        return mz;
    }

    /**
     * 任务状态格式化
     */
    function typeFormatter(data) {
        switch (data) {
            case '0':
                return '待审批';
                break;
            case '1':
                return '审批未通过';
                break;
            case '2':
                return '正常';
                break;
            case '3':
                return '新反馈';
            case '4':
                return '已完成';
            case '5':
                return '退回重办';
            case '9':
                return '待立项';
            default:
                return '未知';
        }
    }

    /**
     * 附件格式化
     */
    var gJFileName = "";

    function fileFormatter(data) {
        if (data == null || data == "") {
            return "无任务附件";
        } else {
            return "<span class='downDetailGJ' gjFile = " + data + " style='width: 40px;cursor: pointer;color: #049CE6;' title='下载'>下载</span>"
        }
    }


    //下载按钮
    $(document).on("click", ".downDetailGJ", function () {
        var url = "/filesUpload/download/" + $(this).attr('gjFile') + "/" + gJFileName;
        window.open(url);
    })
    var rowIds;
    // jqgrid的具体执行方法
    jqgrid({
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",
        autoScroll: false,
        shrinkToFit: true,
        multiselect: false,
        rownumbers: true,
        onSelectRow: function (rowid, status) {
            rowIds = rowid;
            //选择当前的行
            var selectedRowValue = $("#gridTable").jqGrid('getRowData', rowid);
            var types = selectedRowValue.type;//获取任务状态
            //只有已经反馈和待反馈才可以打开
            if (types == "已反馈") {
                $("#comment").attr("disabled", false);
            } else {
                $("#comment").attr("disabled", true);
            }
            if (!status) {
                gridRemoveSelect(rowid);
            } else {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowid) {
                        flag = true;
                        continue;
                    }
                }
                if (!flag) {
                    gridAddSelect(rowid);
                }
            }
        },
        loadComplete: function (data) {
            // var ids = $("#gridTable").jqGrid("getDataIDs");
            // var rowDatas = $("#gridTable").jqGrid("getRowData");//获取所有行的数据
            // for (var i = 0; i<rowDatas.length;i++){
            //     if (data.rows[i].status == 0){
            //         $("#"+ids[i]+ " td").css("color","red");
            //     }
            // }
        },
        onSelectAll: function (aRowids, status) {
            if (!status) {
                aRowids.forEach(function (value, index) {
                    gridRemoveSelect(value);
                });
            } else {
                aRowids.forEach(function (value, index) {
                    var flag = false;
                    for (var i = 0; i < rowids.length; i++) {
                        if (rowids[i] == value) {
                            flag = true;
                            continue;
                        }
                    }
                    if (!flag) {
                        gridAddSelect(value);
                    }
                });
            }
        },
        gridComplete: function () {
            var rowIds = jQuery("#gridTable").jqGrid('getDataIDs');
            for (var k = 0; k < rowIds.length; k++) {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowIds[k]) {
                        flag = true;
                        continue;
                    }
                }
                if (flag && flag == true) {
                    jQuery("#gridTable").setSelection(rowIds[k], true);
                }
            }
        },
        ondblClickRow: function (rowid) {
            var rowData = $('#gridTable').jqGrid('getRowData', rowid).mainName;
            if (rowData.length >= 4) {
                rowData = rowData.substring(0, 4) + "...";
            }
            /**
             * 打开二级页面
             */
            parent.openapp("/taskMain/query2/" + rowid, rowid, rowData)

        }
    });
    jqgrid({
        gridTableId: "#gridTable1",
        gridPagerId: "#gridPager1",
        url: "/taskMain/allCope/",
        autoScroll: false,
        shrinkToFit: false,
        multiselect: false,
        rownumbers: true,
        onSelectRow: function (rowid, status) {
            rowIds = rowid;
            //选择当前的行
            var selectedRowValue = $("#gridTable1").jqGrid('getRowData', rowid);
            var types = selectedRowValue.type;//获取任务状态
            //只有已经反馈和待反馈才可以打开
            if (types == "已反馈") {
                $("#comment").attr("disabled", false);
            } else {
                $("#comment").attr("disabled", true);
            }
            if (!status) {
                gridRemoveSelect(rowid);
            } else {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowid) {
                        flag = true;
                        continue;
                    }
                }
                if (!flag) {
                    gridAddSelect(rowid);
                }
            }
        },
        loadComplete: function (data) {
            // var ids = $("#gridTable").jqGrid("getDataIDs");
            // var rowDatas = $("#gridTable").jqGrid("getRowData");//获取所有行的数据
            // for (var i = 0; i<rowDatas.length;i++){
            //     if (data.rows[i].status == 0){
            //         $("#"+ids[i]+ " td").css("color","red");
            //     }
            // }
        },
        onSelectAll: function (aRowids, status) {
            if (!status) {
                aRowids.forEach(function (value, index) {
                    gridRemoveSelect(value);
                });
            } else {
                aRowids.forEach(function (value, index) {
                    var flag = false;
                    for (var i = 0; i < rowids.length; i++) {
                        if (rowids[i] == value) {
                            flag = true;
                            continue;
                        }
                    }
                    if (!flag) {
                        gridAddSelect(value);
                    }
                });
            }
        },
        gridComplete: function () {
            var rowIds = jQuery("#gridTable").jqGrid('getDataIDs');
            for (var k = 0; k < rowIds.length; k++) {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowIds[k]) {
                        flag = true;
                        continue;
                    }
                }
                if (flag && flag == true) {
                    jQuery("#gridTable").setSelection(rowIds[k], true);
                }
            }
        },
        ondblClickRow: function (rowid) {
            /**
             * 打开二级页面
             */
            parent.openapp("/taskMain/copeUnit/" + rowid, rowid, "抄送我的 ")

        }
    });
    jqgrid({
        gridTableId: "#gridTable2",
        gridPagerId: "#gridPager2",
        url: "/taskCrucial/",
        colNames: colNames2,
        colModel: colModel2,
        autoScroll: false,
        shrinkToFit: false,
        multiselect: false,
        rownumbers: true,
        onSelectRow: function (rowid, status) {
            gJFileName = $('#gridTable2').jqGrid('getRowData', rowid).gJFileName;
            rowIds = rowid;
        },
        ondblClickRow: function (rowid) {
            var rowData = $('#gridTable2').jqGrid('getRowData', rowid).mainName;
            if (rowData.length >= 4) {
                rowData = rowData.substring(0, 4) + "...";
            }
            /**
             * 打开二级页面
             */
            parent.openapp("/taskMain/query2/" + rowid, rowid, rowData)

        }
    });


    //点击开二级页面
    $(document).on("click", "#feedbackBtn", function () {
        var rowData = $('#gridTable').jqGrid('getRowData', rowIds)
        parent.openapp("/taskMain/query2/" + rowIds, rowIds, "单位任务...");
    });

    //攻坚  点击开二级页面
    $(document).on("click", "#urgentSee", function () {
        var rowData = $('#gridTable2').jqGrid('getRowData', rowIds).mainName;
        if (rowData.length >= 4) {
            rowData = rowData.substring(0, 4) + "...";
        }
        /**
         * 打开二级页面
         */
        parent.openapp("/taskMain/query2/" + rowIds, rowIds, rowData);
    });

    //清空选中行
    $("#cancelChecked").click(function () {
        $("#gridTable").jqGrid('resetSelection');
        rowids = [];
    });
    var rowids = [];//选中行id
    /**
     * 取消选中
     */
    function gridRemoveSelect(rowid) {
        rowids.remove(rowid);
    }

    /**
     * 添加选中
     */
    function gridAddSelect(rowid) {
        rowids.push(rowid);
    }

    /**
     * 重写Array
     */
    /*Array.prototype.indexOf = function (val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        }
        return -1;
    };*/

    /**
     * 重写Array
     */
    /*Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };*/


    //导出表

    $("#exportTaskNew").click(function () {
        showExcelDialog({
            url: "/project/exportTaskNew?sysIds=",
            tableId: "#gridTable",
            confirmTitle: "确认对话框",
            confirmMessage: "是否确定导出?",
            confirmOk: "确定",
            confirmCancel: "取消",
            successMessage: "删除成功",
            successTitle: "消息对话框",
            failMessage: "导出失败",
            failTitle: "消息对话框",
            errorTitle: "警告提示框",
            errorMessage: "您当前尚未选中一行，请选择后再试",
            errorOk: "确定"
        });

    })


    //重置表单
    function reset() {
        resetForm("#formDialog form");
    }

    //加载查询对话框
    // $("#queryDialog").load(getUrl("filter"));

    //显示查询对话框
    var queryDialog = $("#queryDialog");
    $("#query").click(function () {
        showDialog({
            dialogTitle: '条件搜素',
            dialogBody: queryDialog,
            dialogFoot: "<button type='button' class='btn btn-primary' onclick='query()'>查询</button>" +
                "<button type='button' class='btn btn-pink' onclick='reset()'>重置</button>" +
                "<button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>"
        });
    });

    //具体查询方法
    function query() {
        var exportData = $('#formDialog form').serialize();
        seachJqgird("#gridTable", "#formDialog form");
        $("#formDialog").modal('hide');
    }

    // 重置创建表单
    function resetCreate() {
        resetForm("#formDialog form");
        // 清除关于会议纪要的内容,及隐藏按钮
        $('#departContent').empty();
        $("#addDepart").css("display", "none");
    }

    // 显示创建对话框
    $("#selectCategory").click(function () {
        loadDialog({
            dialogTitle: '请选择事项类型',
            dialogUrl: getUrl("selectCategory"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="selectCategory()">确认</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    /**
     * 判断模态框
     */
    function selectCategory() {
        var exportData = ($('#formDialog form').serialize().split("="))[1];
        loadDialog({
            tableId: "#gridTable",
            dialogTitle: "会议纪要",
            dialogUrl: getUrl("form") + exportData,
            dialogFoot: '<button type="button" class="btn btn-success" onclick="modify()">确定</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
        });
    }

    // 办结评价
    function comment() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("comment"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }

    //详情
    $("#detail").click(function () {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "任务详情",
            dialogUrl: getUrl("taskMainDetail"),
            dialogFoot: ' <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    });

    //修改
    function modify() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("create"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }

    //任务流程
    $("#flow").click(function () {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "任务流程",
            dialogUrl: getUrl("flow"),
            dialogFoot: '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    });

    //办结评价
    $("#comment").click(function () {
        var ids = jQuery("#gridTable").jqGrid('getGridParam', 'selarrrow');
        if (ids.length == 1) {
            var rowData = jQuery("#gridTable").jqGrid('getRowData', ids);
            /* if (rowData.type != '已反馈') {
                 alertMessage("只有任务状态为已反馈的任务,才可以进行办结评价!");
                 return;
             }*/
        }

        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "办结评价",
            dialogUrl: getUrl("comment"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="comment()">提交</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    });

    //删除
    $("#delete").click(function () {
        showDeleteDialog({
            url: getUrl("delete"),
            tableId: "#gridTable",
            confirmTitle: "确认对话框",
            confirmMessage: "是否确定删除?",
            confirmOk: "确定",
            confirmCancel: "取消",
            successMessage: "删除成功",
            successTitle: "消息对话框",
            failMessage: "删除失败",
            failTitle: "消息对话框",
            errorTitle: "警告提示框",
            errorMessage: "您当前尚未选中一行，请选择后再试",
            errorOk: "确定"
        });
    });

    /**
     * 弹出消息对话框
     * @param msg
     */
    function alertMessage(msg) {
        msg = msg == null ? '' : msg;
        bootbox.dialog({
            title: "消息对话框",
            message: msg,
            buttons: {
                "danger": {
                    "label": '确定',
                    "className": "btn-sm btn-danger"
                }
            }
        });
    }

    /**
     * 修改
     */
    $("#update").click(function () {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "修改任务",
            dialogUrl: getUrl("update"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="updateModify()">修改</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    })

    function updateModify() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("update"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }

    /**
     * NewlyAdded 新增议题
     */
    function addYt() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("addTaskSub"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }

    //立项
    $(document).on("click", ".establish", function () {
        parent.openapp("/taskMain/updateTask/" + rowIds, rowIds, "立项");
    });
    //办理情况导出 handle
    $(document).on("click", ".handle", function () {
        window.open("/taskMain/exportTaskMain?sysId=" + rowIds);
    });
    /*删除任务*/
    $(document).on("click", ".deteleTask", function () {
        var result = confirm('确认删除吗?');
        if (result == true) {
            $.post("/taskMain/delete/" + [rowIds], function (data) {
                if (data.code == 200) {
                    alert("删除成功");
                    setTimeout(function () {
                        //刷新当前页面
                        open(location, '_self').close();
                    }, 50)
                } else {
                    alert("删除失败");
                }
            })
        }
    });

    //删除附件
    $(function () {
        $(".downloadContainer").on("click", ".btn-danger", function () {
            var fileid = $(this).data("fileid");//获取需要删除的文件id
            var filename = $(this).data("filename");//获取需要删除的文件名
            var idStr = $("input[name='file']").val();//获取id字符串
            var nameStr = $("input[name='fileName']").val();//获取文件名字符串
            //    去重文件名和id
            var newStr1 = idStr.replace(fileid + ",", "");
            var newStr2 = nameStr.replace(filename + ",", "");
            //重新赋值
            $("input[name='file']").val(newStr1);
            $("input[name='fileName']").val(newStr2);
            $(this).parent().remove();//移出当前父元素
        });
    })
    /*修改任务*/
    $(document).on("click", ".modify", function () {
        $.get("/taskMain/updateMain/" + rowIds, function (data) {
            //判断有附件显示
            if (data.taskMain.files === undefined) {
                $("input[name='file']").val("");
                $("input[name='fileName']").val("");
                var htmls = '\
              <input type="text" readonly value="暂无附件">  \
                ';
                $(".downloadContainer").html(htmls);
            } else {
                var fileHtml = "";
                var items = data.taskMain.files;
                for (var i = 0; i < items.length; i++) {
                    fileHtml += ' \<div style="margin-bottom:6px;"><input style="width: 60%;" type="text" value="' + items[i].fileName + '"  placeholder="' + items[i].fileName + '"   title="' + items[i].fileName + '">\
               <button class="btn btn-primary file" onclick="download2(this)"  FileSysId="' + items[i].file + '">下载附件</button><button class="btn btn-danger" data-fileid="' + items[i].file + '" data-filename="' + items[i].fileName + '">删除</div></div>\
                    ';
                }
                $(".downloadContainer").html(fileHtml);
                //获取组装文件名和文件id 字符串
                var fileIds1 = "";
                var fileNames1 = "";
                for (var i = 0; i < items.length; i++) {
                    $("input[name='file']").val(fileIds1 += items[i].file + ",");
                    $("input[name='fileName']").val(fileNames1 += items[i].fileName + ",");
                }
            }
            $("input[name='mainName']").val(data.taskMain.mainName);  //主任务
            $("textarea[name='content']").val(data.taskMain.content);//内容
            if (data.taskMain.timeType != 1) {                           //只判断单时限时候出现
                $("input[name='timeLimit']").parent().parent().hide()
            }
            $("input[name='timeLimit']").val(data.taskMain.timeLimit);//时限
            // $("#temporaryFile").val(data.taskMain.file);//附件
            // $("#temporaryFileName").val(data.taskMain.fileName);//附件
            $("input[name='sysId']").val(data.taskMain.sysId);
            $("button[FileSysId]").attr("FileSysId", data.taskMain.file).siblings("input").val(data.taskMain.fileName);


            <%--多文件上传--%>
            var str1 = fileIds1;//附件id字符串
            var str2 = fileNames1;//附件名字字符串
            var fileStr = "";//id字符串拼接
            var fileNameStr = "";//文件名字符串拼接
            if (str1 === null || str1 === undefined) {
                fileStr = "";
                fileNameStr = "";
            } else {
                fileStr = str1;
                fileNameStr = str2;
            }

            var uploader = easyUploader({
                id: "uploader",
                accept: '.jpg,.png,.doc,.docx,.pdf,.xls,.xlsx,.ppt,.pptx',
                action: '/filesUpload/uploadFiles',
                dataFormat: 'formData',
                maxCount: 10,//允许上传的个数
                maxSize: 2000,//允许上传最大的容量
                multiple: true,
                data: null,
                beforeUpload: function (file, data, args) {
                },
                onChange: function (fileList) {
                },
                onRemove: function (removedFiles, files) {
                    console.log('onRemove', removedFiles);
                },
                onSuccess: function (res) {
                    console.log('onSuccess', res);
                    if (res.data !== undefined && res.data[0] !== undefined) {
                        //拼接文件id 和 文件名
                        console.log(fileStr);
                        $("input[name='file']").val(fileStr += res.data[0].sysid + ",");
                        $("input[name='fileName']").val(fileNameStr += res.data[0].oldName + ",");

                    }
                },
                onError: function (err) {
                    console.log('onError', err);
                },
            });

        });
        $("#modify").modal("show");
    })

    /*修改确认*/
    $(".confirmModify").click(function () {
        if ($("input[name=fileName]").length > 1) {
            $("#temporaryFileName").remove();
        }
        if ($("input[name=file]").length > 1) {
            $("#temporaryFile").remove();
        }
        var datas = {
            mainName: $("input[name='mainName']").val(),  //主任务
            content: $("textarea[name='content']").val(),//内容
            timeLimit: $("input[name='timeLimit']").val(),//时限
            file: $("input[name='file']").val(),//附件
            fileName: $("input[name='fileName']").val(),//附件Name
            sysId: $("input[name='sysId']").val()
        }
        $.post("/taskMain/updateMain/", datas, function (data) {
            if (data.code == "200") {
                alert("修改成功");
                setTimeout(function () {
                    open(location, '_self').close();
                }, 50)
            }
        })
    })

    function minDate() {
        var now = new Date();
        return now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + (now.getDate() + 1);
    }

    $(document).on("click", ".date_picker", function () {
        laydate({
            elem: this,
            min: minDate()
        });
    });
    $(function () {
        getGenre(".searchType");

        //    承办单位下拉框
        $("#deptIds1").select2({
            placeholder: "请输入或点击选择承办单位",
            width: "210px",
            closeOnSelect: false,
            allowClear: true,
        });
        //请求承办单位下拉框
        requestDept();
    })


    /**未完成
     */
    $("#noFinish").click(function () {
        var categoryId = $(".searchType").val();//获取事项类型
        var deptId = $(".deptrespts").val();//获取承办单位
        var beginTime = $(".beginTimes").val();//获取开始时间
        var endTime = $(".endTimes").val();//获取结束时间
        var search = $(".searchs").val();//搜索字段
        var status = '!4';//任务状态：未完成
        var data = {
            categoryId: categoryId,
            deptId: deptId,
            search: search,
            startTime: beginTime,
            endTime: endTime,
            status: status
        }
        $("#gridTable").jqGrid('setGridParam', {
            url: "/taskMain/allMain/",
            postData: data, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });
    /**已完成
     */
    $("#finished").click(function () {
        var categoryId = $(".searchType").val();//获取事项类型
        var deptId = $(".deptrespts").val();//获取承办单位
        var beginTime = $(".beginTimes").val();//获取开始时间
        var endTime = $(".endTimes").val();//获取结束时间
        var search = $(".searchs").val();//搜索字段
        var status = '4';//任务状态：已完成
        var data = {
            categoryId: categoryId,
            deptId: deptId,
            search: search,
            startTime: beginTime,
            endTime: endTime,
            status: status
        }
        $("#gridTable").jqGrid('setGridParam', {
            url: "/taskMain/allMain/",
            postData: data, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });
    /**全部任务
     */
    $("#allMain").click(function () {
        var data = {
        }
        $("#gridTable").jqGrid('setGridParam', {
            url: "/taskMain/allMain/",
            postData: data, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });
</script>

</body>
</html>